# 将官方的ubuntu运行时用作父镜像
FROM registry.cn-hangzhou.aliyuncs.com/jinjimi/ubuntu:18.04

# 复制java_policy文件到/etc目录下
COPY build/java_policy /etc

# 安装依赖库到容器
RUN buildDeps='software-properties-common git libtool cmake python-dev python3-pip python-pip libseccomp-dev' && \
    apt-get update && apt-get install -y python python3.5 python-pkg-resources python3-pkg-resources gcc g++ $buildDeps && \
    add-apt-repository ppa:openjdk-r/ppa && apt-get update && apt-get install -y openjdk-8-jdk && \
    pip3 install --no-cache-dir psutil gunicorn flask requests && \
    cd /tmp && git clone -b master  --depth 1 https://gitee.com/jinjimmy/education-judger.git && cd education-judger && \
    mkdir build && cd build && cmake .. && make && make install && cd ../bindings/Python && python3 setup.py install && \
    apt-get purge -y --auto-remove $buildDeps && \
    apt-get clean && rm -rf /var/lib/apt/lists/* && \
    mkdir -p /code && \
    useradd -u 12001 compiler && useradd -u 12002 code && useradd -u 12003 spj && usermod -a -G code spj

# 间隔5秒进行一次健康检查，尝试3次，并执行service.py脚本
HEALTHCHECK --interval=5s --retries=3 CMD python3 /code/service.py

#　将当前的server目录内容复制到/code中的容器中
ADD server /code

# 将工作目录设置为/code
WORKDIR /code

# 执行gcc编译并生成动态库文件
RUN gcc -shared -fPIC -o unbuffer.so unbuffer.c

# 使端口8080可供此容器外的环境使用
EXPOSE 8080

ENTRYPOINT /code/entrypoint.sh
